package Service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import DAO.MarketDAO;
import Entity.Market;
import Helpers.MarketHelper;
import VOs.MarketVO;

public class MarketService {

	public void create(MarketVO companyVo, EntityManager em) {
		Market market = new Market();
		MarketDAO.create(market, em);
	}

	public List<MarketVO> readMarkets(EntityManager em) {
		List<Market> markets = MarketDAO.readMarkets(em);
		ArrayList<MarketVO> marketsVOs = new ArrayList<MarketVO>(markets.size());
		for (Market market : markets) {
			marketsVOs.add(market.tovo());
		}
		return marketsVOs;
	}

	public void update(MarketVO companyVo, MarketVO newOne, EntityManager em) {
		Market oldMarket = new Market();

		Market newMarket = new Market();

		MarketDAO.update(newMarket, em);
	}

	public void delete(MarketVO companyVo, EntityManager em) {
		Market market = new MarketHelper().toEntity(companyVo);
		MarketDAO.delete(market, em);
	}

}
